package br.ucb.ucblive.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;



import br.ucb.ucblive.HIB.DisciplinaHIB;
import br.ucb.ucblive.beans.Disciplina;


@FacesConverter (value="DisciplinaConverter")
public class DisciplinaConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		DisciplinaHIB disciplinaHib = new DisciplinaHIB();
		if (value == null)
			return null;
		try {
			return disciplinaHib.consultar(Integer.parseInt(value));
		} catch (Exception e) {
			e.printStackTrace();
			return new Object();
		}
	}

	@Override
	public String getAsString(FacesContext context, UIComponent componente, Object object) {
		if (object == null)
			return null;
		Disciplina disciplina = (Disciplina) object;	
		return Integer.toString(disciplina.getIdDisciplina());
	}


}
